package view;

import mock.MockGameState;
import model.GameState;
import model.Task;
import model.TeamState;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Student
 * Date: 29/11/12
 * Time: 16:22
 * To change this template use File | Settings | File Templates.
 */
public class BoardPanel extends JPanel {

    public BoardPanel() {
        setBorder(BorderFactory.createTitledBorder("Game Board"));
        setLayout(new FlowLayout());

    }

    public BoardPanel(GameState gameState) {
        this();
        populateBoard(gameState);
    }

    public void addTeamStatus(String name, Color color, List<Task> backlog, List<List<Task>> progress, List<Task> done, List<Integer> dice) {
        JComponent teamPanel = new TeamPanel(name, color, backlog, progress, done, dice);
        add(teamPanel);
    }

    public void populateBoard(GameState gameState) {
        List<TeamState> teamStates = gameState.getTeamStates();
        setLayout(new GridLayout(teamStates.size() / 2, 2));
        for (TeamState teamState : teamStates) {
            addTeamStatus(teamState.getName(),
                    teamState.getColor(),
                    teamState.getBacklog(),
                    teamState.getProgress(),
                    teamState.getDone(),
                    teamState.getDice());
        }
    }

    public void clearBoard() {
        removeAll();
        repaint();
    }

    public void updateBoard(GameState gameState) {
        populateBoard(gameState);
        revalidate();
        repaint();
    }
}
